var i = 1;
window.onload = function () {
    var iTimerid = window.setInterval("change()", 4000);

    var list=document.getElementsByClassName("pictureContainer")[0].getElementsByClassName("tabBar")[0].getElementsByTagName("a");
    for(j=0;j<list.length;j++){
        list[j].index = j;
        list[j].onclick = function(){
            switchPic(this.index);
        }
    }

    var pre=document.getElementById("pre");
    pre.onclick = function(){
        i=(i+3)%4;
        switchPic(i);
    }
    
    var pre=document.getElementById("next");
    pre.onclick = function(){
        i=(i+1)%4;
        switchPic(i);
    }
}
function change() {
    i = i % 4;
    switchPic(i);
    i++;
}
function switchPic(n){
    switch (n) {
        case 0:
            document.getElementsByClassName("pictureContainer")[0].getElementsByTagName("img")[0].src = "../images/ad3.jpg";
            break;
        case 1:
            document.getElementsByClassName("pictureContainer")[0].getElementsByTagName("img")[0].src = "../images/ad4.jpg";
            break;
        case 2:
            document.getElementsByClassName("pictureContainer")[0].getElementsByTagName("img")[0].src = "../images/ad5.jpg";
            break;
        case 3:
            document.getElementsByClassName("pictureContainer")[0].getElementsByTagName("img")[0].src = "../images/ad6.jpg";
            break;
    }
}